package com.szqhyxj.youxiangju;

import android.app.Dialog;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.szqhyxj.youxiangju.sys.util.ToastUtils;

public abstract class BasePromptFragment extends LazyFragment implements PromptView{

    private Dialog dialog;

    @Override
    public void showToast(String msg){
        ToastUtils.showTost(getContext(),msg);
    }
    @Override
    public void showLoading(String msg) {
        if (dialog != null && dialog.isShowing()) return;
        dialog = new Dialog(getContext(), R.style.Dialog);
        View view = getLayoutInflater().inflate(R.layout.pro_dialog_toash, null);

        TextView txt = (TextView) view.findViewById(R.id.txt_content);
        txt.setText(msg);

        dialog.addContentView(view, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
    }

    @Override
    public void showLoading() {
        if (dialog != null && dialog.isShowing()) return;
        dialog = new Dialog(getContext(), R.style.Dialog);
        View view = getLayoutInflater().inflate(R.layout.pro_dialog_toash, null);

        TextView txt = (TextView) view.findViewById(R.id.txt_content);
        txt.setText("加载中..");

        dialog.addContentView(view, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
    }
    @Override
    public void dismissLoading() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
            dialog = null;
        }
    }
}